#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "/usr/include/glib-2.0/glib.h"

/*
 * gcc -o glib_str glib_str.c -I/usr/include/glib-2.0/ -lglib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include
 */

int main(int argc, char *argv[])
{
	int ret = 0;

	if(argc != 3)
	{
		fprintf(stderr,"Usage: %s <string> <delim>\n",strrchr(argv[0],'/')+1);
		exit(1);
	}

	char **parts = g_strsplit(argv[1],argv[2],-1);
	if(parts==NULL)
	{
		printf("g_strsplit error!\n");
		exit(2);
	}
	unsigned int part_len = g_strv_length(parts);
	printf("string parts length = %u\n",part_len);
	int i = 0;
	for(i=0;i<part_len&&parts[i];i++)
	{
		printf("\tparts[%d] = %s\n",i,parts[i]);
	}
	printf("parts[%d] = %p\n",i,parts[i]);
	g_strfreev(parts);
	exit(0);
}


